package com.company.ywj;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Bike {

    public static void main(String[] args) {
        // write your code here
        String[] ranking = {"1", "2", "3", "4"};
        String[] color = {"red", "purple", "blue", "green"};
        String[] name = {"Mike", "Ellie", "Rohan", "Fatma"};
        List<String[]> list = new ArrayList<String[]>();
        list.add(ranking);
        list.add(color);
        list.add(name);
        List<Result> result = new ArrayList<Result>();
        for (int i = 0; i < ranking.length; i++) {
            for (int j = 0; j < color.length; j++) {
                for (int k = 0; k < name.length; k++) {
                    Result result1 = new Result(ranking[i], color[j], name[k]);
                    // Ellie骑紫色的车->骑紫色车的不是Ellie为否，Ellie骑的不是紫色车为否
                    if ((result1.getColor() == "purple" & result1.getName() != "Ellie") | (result1.getName() == "Ellie" & result1.getColor() != "purple")) {
                        continue;
                    }
                    // Rohan没有骑绿色的车->骑绿色和紫色车的Rohan为否
                    if (result1.getName() == "Rohan" & (result1.getColor() == "green" | result1.getColor() == "purple")) {
                        continue;
                    }
                    //Mike和Ellie不是第一，也不是最后->第一和第四是Mike和Ellie的为否，第二和第三是Rohan和Fatma的为否
                    if (result1.getRanking() == "1" | result1.getRanking() == "4") {
                        if (result1.getName() == "Mike" | result1.getName() == "Ellie") {
                            continue;
                        }
                    } else if (result1.getName() == "Rohan" | result1.getName() == "Fatma") {
                        continue;
                    }
                    //骑蓝色车的人领先Fatma->骑蓝色车的人是Fatma为否，Fatma是第一为否，Rohan最后为否
                    if (result1.getColor() == "blue" & result1.getName() == "Fatma") {
                        continue;
                    }
                    if (result1.getName() == "Fatma") {
                        if (result1.getRanking() == "1") {
                            continue;
                        }
                    } else {
                        if (result1.getRanking() == "4") {
                            continue;
                        }
                    }
                    //骑绿色车的人领先骑紫色车的人->绿车是最后一名为否
                    if (result1.getColor() == "green" & result1.getRanking() == "4") {
                        continue;
                    }
                    result.add(result1);
                }
            }
        }
        //骑绿色车的人领先骑紫色车的人
        for (int i = 0; i < result.size(); i++) {
            Result s = (Result) result.get(i);
            if (s.getColor() == "green") {
                for (int j = 0; j < result.size(); j++) {
                    Result t = (Result) result.get(j);
                    if (t.getColor() == "purple") {
                        if (t.getRanking().compareTo(s.getRanking()) < 0) {
                            t.setJudge(false);
                            result.set(j, t);
                        }
                        if (s.getRanking().compareTo(t.getRanking()) > 0) {
                            s.setJudge(false);
                            result.set(i, s);
                        }
                    }
                }
            }
        }

        //清除多余矛盾项
        clean(result);

        //输出
        for (int i = 0; i < result.size(); i++) {
            Result s = (Result) result.get(i);
            if (s.getJudge() == true) {
                System.out.println(s.toString());
            }

        }
    }
    public static void clean (List < Result > result) {
        int[] number = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(0, "1");
        map.put(1, "2");
        map.put(2, "3");
        map.put(3, "4");
        map.put(4, "Mike");
        map.put(5, "Ellie");
        map.put(6, "Rohan");
        map.put(7, "Fatma");
        map.put(8, "red");
        map.put(9, "purple");
        map.put(10, "blue");
        map.put(11, "green");
        for (int i = 0; i < result.size(); i++) {
            Result s = (Result) result.get(i);
            if (s.getJudge() == true) {
                if (s.getRanking() == "1") {
                    number[0]++;
                } else if (s.getRanking() == "2") {
                    number[1]++;
                } else if (s.getRanking() == "3") {
                    number[2]++;
                } else if (s.getRanking() == "4") {
                    number[3]++;
                }
                if (s.getName() == "Mike") {
                    number[4]++;
                } else if (s.getName() == "Ellie") {
                    number[5]++;
                } else if (s.getName() == "Rohan") {
                    number[6]++;
                } else if (s.getName() == "Fatma") {
                    number[7]++;
                }
                if (s.getColor() == "red") {
                    number[8]++;
                } else if (s.getColor() == "purple") {
                    number[9]++;
                } else if (s.getColor() == "blue") {
                    number[10]++;
                } else if (s.getColor() == "green") {
                    number[11]++;
                }
            }
        }
        //排名
        for (int i = 0; i < 4; i++) {
            if (number[i] == 1) {
                Result temp = new Result();
                int index = 0;
                for (int j = 0; j < result.size(); j++) {
                    Result s = (Result) result.get(j);
                    if (s.getJudge() == true) {
                        if (s.getRanking() == map.get(i)) {
                            temp = s;
                            index = j;
                            break;
                        }
                    }
                }
                for (int j = 0; j < result.size(); j++) {
                    Result s = (Result) result.get(j);
                    if (s.getJudge() == true) {
                        if (j != index) {
                            if (s.getColor().compareTo(temp.getColor()) == 0 | s.getName().compareTo(temp.getName()) == 0) {
                                s.setJudge(false);
                                for (int k = 0; k < number.length; k++) {
                                    if (map.get(k) == s.getRanking() | map.get(k) == s.getColor() | map.get(k) == s.getName()) {
                                        number[k]--;
                                    }
                                }
                            }
                        }
                    }
                }
            }

        }
        //姓名
        for (int i = 4; i < 8; i++) {
            if (number[i] == 1) {
                Result temp = new Result();
                int index = 0;
                for (int j = 0; j < result.size(); j++) {
                    Result s = (Result) result.get(j);
                    if (s.getJudge() == true) {
                        if (s.getName() == map.get(i)) {
                            temp = s;
                            index = j;
                            break;
                        }
                    }
                }
                for (int j = 0; j < result.size(); j++) {
                    Result s = (Result) result.get(j);
                    if (s.getJudge() == true) {
                        if (j != index) {
                            if (s.getColor().compareTo(temp.getColor()) == 0 | s.getRanking().compareTo(temp.getRanking()) == 0) {
                                s.setJudge(false);
                                for (int k = 0; k < number.length; k++) {
                                    if (map.get(k) == s.getRanking() | map.get(k) == s.getColor() | map.get(k) == s.getName()) {
                                        number[k]--;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        //颜色
        for (int i = 8; i < 12; i++) {
            if (number[i] == 1) {
                Result temp = new Result();
                int index = 0;
                for (int j = 0; j < result.size(); j++) {
                    Result s = (Result) result.get(j);
                    if (s.getJudge() == true) {
                        if (s.getName() == map.get(i)) {
                            temp = s;
                            index = j;
                            break;
                        }
                    }
                }
                for (int j = 0; j < result.size(); j++) {
                    Result s = (Result) result.get(j);
                    if (s.getJudge() == true) {
                        if (j != index) {
                            if (s.getRanking().compareTo(temp.getRanking()) == 0 | s.getName().compareTo(temp.getName()) == 0) {
                                s.setJudge(false);
                                for (int k = 0; k < number.length; k++) {
                                    if (map.get(k) == s.getRanking() | map.get(k) == s.getColor() | map.get(k) == s.getName()) {
                                        number[k]--;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
